from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.common.by import By

from demo.xueqiuAppium.page.base_page import BasePage


class Search(BasePage):
	# _driver: WebDriver
	#
	# def __init__(self, driver):
	# 	self._driver = driver

	# todo 多平台、多版本、可能多个定位符
	# _locator = (By.ID, 'search_input_text')
	_name_locator = (By.ID, 'name')

	def search(self):
		self.find(MobileBy.ID, 'search_input_text').send_keys('alibaba')
		self.find(self._name_locator).click()
		return self

	def get_price(self) -> float:
		# self.find(self._locator).send_keys('alibaba')
		# self.find(By.ID, 'name').click()
		# price = float(self.find(By.ID, 'current_price').get_attribute('text'))
		# return price
		return float(self.find(By.ID, 'current_price').text)

	def add_select(self):
		ele = self.find_by_text('加自选')
		ele.click()
		return self

	def un_select(self):
		ele = self.find_by_text('已添加')
		ele.click()
		return self

	def get_msg(self):
		return self.find_and_get_text(By.ID, 'followed_btn')
		# return self.find_and_get_text1(By.ID, 'followed_btn')
		# return self.find(By.ID, 'followed_btn').text

	def aaa(self):
		self.find(By.XPATH, '//*[@text="下次再说"]').click()


